To calculate the power of a number.
def calculate_power(base, exponent):
return base ** exponent
def calculate_and_display_power():
base = float(input("Enter the base number: "))
exponent = float(input("Enter the exponent: "))
result = calculate_power(base, exponent)
print("Result:", result)
# Example 1
calculate_and_display_power()
Enter the base number: 3
Enter the exponent: 4
Result: 81.0
Enter the base number: 2
Enter the exponent: 5
Result: 32.0
The function calculate_power(base, exponent)
calculates the power of a number raised to an exponent using Python's exponentiation operator (**).
The function calculate_and_display_power()
takes input for the base number and the exponent, calculates the power using the first function, and displays the result.